package com.goodluck.goodluckim.sdk.msg;

import android.util.SparseArray;

import com.chad.library.adapter.base.util.ProviderDelegate;
import com.goodluck.goodluckim.db.model.IMMessage;
import com.goodluck.goodluckim.ui.msg.viewholder.MsgViewHolderBase;

/**
 * Created by wyj on 2018/9/17.
 */

public abstract class MsgViewHolderFactory {
    protected SparseArray<MsgViewHolderBase> mViewHolders = new SparseArray<>();
    private int viewType;

    public int getViewType(IMMessage message) {
        return mViewHolders.get(message.getMessageType()).viewType();
    }

    public void addItemType(int msgType, MsgViewHolderBase msgViewHolderBase, ProviderDelegate providerDelegate) {
        msgViewHolderBase.setViewType(viewType);
        viewType++;
        mViewHolders.put(msgType, msgViewHolderBase);
        providerDelegate.registerProvider(msgViewHolderBase);
    }

    public abstract void registerProviders(ProviderDelegate providerDelegate);
}
